package VUTHANHPHUC_HOMEWORK_OOP;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.xml.crypto.KeySelector.Purpose;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PoundView extends JFrame {

	private JPanel contentPane;
	private JTextField txtInput;
	private JTextField txtKQ;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					PoundView frame = new PoundView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public PoundView() {
		setTitle("Convert Kilogram to Pounds");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 409, 270);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Convert Kilogram to Pounds");
		lblNewLabel.setForeground(Color.RED);
		lblNewLabel.setBounds(10, 14, 174, 14);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Input a Kilogram");
		lblNewLabel_1.setBounds(17, 39, 106, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Results");
		lblNewLabel_2.setBounds(20, 143, 103, 14);
		contentPane.add(lblNewLabel_2);
		
		JButton Convert = new JButton("Convert to Pounds");
		Convert.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(txtInput.getText().isEmpty()){
					JOptionPane.showMessageDialog(getParent(), "Yêu cầu nhập vào số Kilogram", "Lỗi", JOptionPane.ERROR_MESSAGE);
				}else{
					Pound objP = new Pound();
					double kg = Double.parseDouble(txtInput.getText());
					objP.setKg(kg);
					PoundControllers objC = new PoundControllers(objP);
					txtKQ.setText("+Result: " + kg + " Kilogram = " + objC.ConterToPound() + " Pounds");
				}
			}
		});
		Convert.setBounds(218, 67, 147, 23);
		contentPane.add(Convert);
		
		txtInput = new JTextField();
		txtInput.setBounds(133, 36, 232, 20);
		contentPane.add(txtInput);
		txtInput.setColumns(10);
		
		txtKQ = new JTextField();
		txtKQ.setBounds(133, 107, 232, 86);
		contentPane.add(txtKQ);
		txtKQ.setColumns(10);
	}
}
